package com.springbootblog.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ElasticSearchConfig
{
    @Value("${spring.elasticsearch.ip}")
    private String hostname;

    @Value("${spring.elasticsearch.port}")
    private Integer port;

    @Value("${spring.elasticsearch.protocol}")
    private String protocol;

    // 注册 rest高级客户端
    @Bean
    public RestHighLevelClient restHighLevelClient()
    {
        // System.out.println(hostname);
        // System.out.println(port);
        // System.out.println(protocol);
        RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(
                        new HttpHost(hostname, port, protocol)
                )
        );
        return client;
    }
}